package client.model;

import java.util.ArrayList;
import java.util.Collection;

import client.controller.Virtual3DController;

public class Universe3D {
	
	private Collection<Virtual3DController> objects;
	private Collection<Virtual3DController> viewpoints;
	private Virtual3DController selectedViewpoint;
	
	public Universe3D() {
		objects = new ArrayList<Virtual3DController>();
		viewpoints = new ArrayList<Virtual3DController>();
		selectedViewpoint = null;
	}
	
	public boolean contains(String n) {
		boolean result = false;
		Virtual3DController object = this.getObject(n);
		if(object == null) {
			object = this.getViewpoint(n);
			if(object != null) {
				result = true;
			}
		}
		else {
			result = true;
		}
		return result;
	}
	
	public void addObject(Virtual3DController o) {
		objects.add(o);
	}
	
	public void addViewpoint(Virtual3DController v) {
		viewpoints.add(v);
	}
	
	public boolean selectViewpoint(Virtual3DController v) {
		boolean result = false;
		if(viewpoints.contains(v)) {
			result = true;
			selectedViewpoint = v;
		}
		return result;
	}
	
	public Virtual3DController getSelectedViewpoint() {
		return selectedViewpoint;
	}
	
	public Collection<Virtual3DController> getViewpoints() {
		return viewpoints;
	}
	
	public Collection<Virtual3DController> getObjects() {
		return objects;
	}
	
	public Virtual3DController getObject(String name) {
		Virtual3DController result = null;
		for (Virtual3DController o : objects) {
			if(o.getName().equals(name)) {
				result = o;
			}
		}
		return result;
	}
	
	public Virtual3DController getViewpoint(String name) {
		Virtual3DController result = null;
		for (Virtual3DController v : viewpoints) {
			if(v.getName().equals(name)) {
				result = v;
			}
		}
		return result;
	}

}
